package pms.controller;

import java.util.Date;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import pms.om.Person;

/** 
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
 * @author josef@dr-schneeberger.de
 */
public class BilderAufnehmen extends AllePersonen {
	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		httpServletRequest.setCharacterEncoding("UTF-8");
		int id = 0 ;
		
        //String ImagePath = System.getProperty("user.dir") + "\\WebContent\\images\\dbImages\\SeriesImage";
		String ImagePath = "c:\\workspace\\hbi\\WebContent\\images\\dbImages\\SeriesImage";

//        String ImagePath = "C:\\Studium\\tk\\FH\\Semester 7\\Progammierung Multimedialer Systeme\\Project\\PMS\\hbi\\WebContent\\images\\dbImages\\SeriesImage";
        
		File file1 = new File(ImagePath + "/image" + 0 + ".jpg");
    	File file2 = new File(ImagePath + "/image" + 1 + ".jpg");
    	File file3 = new File(ImagePath + "/image" + 2 + ".jpg");
    	File file4 = new File(ImagePath + "/image" + 3 + ".jpg");
    	File file5 = new File(ImagePath + "/image" + 4 + ".jpg");
    	File file6 = new File(ImagePath + "/image" + 5 + ".jpg");
    	File file7 = new File(ImagePath + "/image" + 6 + ".jpg");
    	File file8 = new File(ImagePath + "/image" + 7 + ".jpg");
    	File file9 = new File(ImagePath + "/image" + 8 + ".jpg");
    	File file10 = new File(ImagePath + "/image" + 9 + ".jpg");
    	File file11 = new File(ImagePath + "/image" + 10 + ".jpg");
    	File file12 = new File(ImagePath + "/image" + 11 + ".jpg");
    	File file13 = new File(ImagePath + "/image" + 12 + ".jpg");
    	File file14 = new File(ImagePath + "/image" + 13 + ".jpg");
    	File file15 = new File(ImagePath + "/image" + 14 + ".jpg");
    	File file16 = new File(ImagePath + "/image" + 15 + ".jpg");
    	
    	byte[] bFile1 = new byte[(int) file1.length()];
    	byte[] bFile2 = new byte[(int) file2.length()];
    	byte[] bFile3 = new byte[(int) file3.length()];
    	byte[] bFile4 = new byte[(int) file4.length()];
    	byte[] bFile5 = new byte[(int) file5.length()];
    	byte[] bFile6 = new byte[(int) file6.length()];
        byte[] bFile7 = new byte[(int) file7.length()];
    	byte[] bFile8 = new byte[(int) file8.length()];
    	byte[] bFile9 = new byte[(int) file9.length()];
    	byte[] bFile10 = new byte[(int) file10.length()];
    	byte[] bFile11 = new byte[(int) file11.length()];
    	byte[] bFile12 = new byte[(int) file12.length()];
    	byte[] bFile13 = new byte[(int) file13.length()];
    	byte[] bFile14 = new byte[(int) file14.length()];
    	byte[] bFile15 = new byte[(int) file15.length()];
    	byte[] bFile16 = new byte[(int) file16.length()];
 	
        try {
         //convert file into array of bytes
	     FileInputStream fileInputStream1 = new FileInputStream(file1); fileInputStream1.read(bFile1); fileInputStream1.close();
	     FileInputStream fileInputStream2 = new FileInputStream(file2); fileInputStream2.read(bFile2); fileInputStream2.close();
	     FileInputStream fileInputStream3 = new FileInputStream(file3); fileInputStream3.read(bFile3); fileInputStream3.close();
	     FileInputStream fileInputStream4 = new FileInputStream(file4); fileInputStream4.read(bFile4); fileInputStream4.close();
	     FileInputStream fileInputStream5 = new FileInputStream(file5); fileInputStream5.read(bFile5); fileInputStream5.close();
	     FileInputStream fileInputStream6 = new FileInputStream(file6); fileInputStream6.read(bFile6); fileInputStream6.close();
	     FileInputStream fileInputStream7 = new FileInputStream(file7); fileInputStream7.read(bFile7); fileInputStream7.close();
	     FileInputStream fileInputStream8 = new FileInputStream(file8); fileInputStream8.read(bFile8); fileInputStream8.close();
	     FileInputStream fileInputStream9 = new FileInputStream(file9); fileInputStream9.read(bFile9); fileInputStream9.close();
	     FileInputStream fileInputStream10 = new FileInputStream(file10); fileInputStream10.read(bFile10); fileInputStream10.close();
	     FileInputStream fileInputStream11 = new FileInputStream(file11); fileInputStream11.read(bFile11); fileInputStream11.close();
	     FileInputStream fileInputStream12 = new FileInputStream(file12); fileInputStream12.read(bFile12); fileInputStream12.close();
	     FileInputStream fileInputStream13 = new FileInputStream(file13); fileInputStream13.read(bFile13); fileInputStream13.close();
	     FileInputStream fileInputStream14 = new FileInputStream(file14); fileInputStream14.read(bFile14); fileInputStream14.close();
	     FileInputStream fileInputStream15 = new FileInputStream(file15); fileInputStream15.read(bFile15); fileInputStream15.close();
	     FileInputStream fileInputStream16 = new FileInputStream(file16); fileInputStream16.read(bFile16); fileInputStream16.close();} 
	     catch (Exception e) {
	     e.printStackTrace();
        }
		
		List allePers = getPersonDao().findAll() ;
		id = allePers.size() ;
		Person p = getPersonDao().findById(id) ;
		p.setPicture1(bFile1) ;
		p.setPicture2(bFile2) ;
		p.setPicture3(bFile3) ;
		p.setPicture4(bFile4) ;
		p.setPicture5(bFile5) ;
		p.setPicture6(bFile6) ;
		p.setPicture7(bFile7) ;
		p.setPicture8(bFile8) ;
		p.setPicture9(bFile9) ;
		p.setPicture10(bFile10) ;
		p.setPicture11(bFile11) ;
		p.setPicture12(bFile12) ;
		p.setPicture13(bFile13) ;
		p.setPicture14(bFile14) ;
		p.setPicture15(bFile15) ;
		p.setPicture16(bFile16) ;
		getPersonDao().modify(p) ;
		return super.handleRequestInternal(httpServletRequest, httpServletResponse);
	}

}
